/*
 * File: E:\Kan\ARM\Projects\Google Code\Umrichter\trunk\SimulinkModelle\slprj\ert\_sharedutils\plook_u32u16u32n31_bincp_f.c
 *
 * Code generated for Simulink model 'Fu_Foc'.
 *
 * Model version                  : 1.270
 * Simulink Coder version         : 8.2 (R2012a) 29-Dec-2011
 * TLC version                    : 8.2 (Dec 29 2011)
 * C/C++ source code generated on : Sun Apr 28 18:42:25 2013
 */

#include "rtwtypes.h"
#include "rtw_shared_utils.h"

uint32_T plook_u32u16u32n31_bincp_f(uint16_T u, const uint16_T bp[], uint32_T
  maxIndex, uint32_T *fraction, uint32_T *prevIndex)
{
  uint32_T bpIndex;
  uint32_T startIndex;

  /* Prelookup - Index and Fraction
     Index Search method: 'binary'
     Extrapolation method: 'Clip'
     Use previous index: 'on'
     Use last breakpoint for index at or above upper limit: 'off'
     Remove protection against out-of-range input in generated code: 'off'
     Rounding mode: 'floor'
   */
  if (u <= bp[0U]) {
    bpIndex = 0U;
    *fraction = 0U;
  } else if (u < bp[maxIndex]) {
    startIndex = *prevIndex;
    bpIndex = binsearch_u32u16_prevIdx(u, bp, startIndex, maxIndex);
    *fraction = div_repeat_u32((uint32_T)(uint16_T)((uint32_T)u - (uint32_T)
      bp[bpIndex]) << 16, (uint32_T)(uint16_T)((uint32_T)bp[bpIndex + 1U] -
      (uint32_T)bp[bpIndex]), 15U);
  } else {
    bpIndex = maxIndex - 1U;
    *fraction = 2147483648U;
  }

  *prevIndex = bpIndex;
  return bpIndex;
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
